﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using MINERP.BLL.Statistics;

namespace MINERP.Statistics.Forms
{
    public partial class FrmComPerf : Form
    {
        public FrmComPerf()
        {
            InitializeComponent();
        } 
        ComPerfBLL _bll=new ComPerfBLL();
        private static FrmComPerf instance = null;
        public static FrmComPerf GetInstance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmComPerf();

                }
                return instance;
            }
        }
        private void FrmComPerf_Load(object sender, EventArgs e)
        {

        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                DateTime startTime = Convert.ToDateTime(dateTimePickerStart.Text).Date;
                DateTime endTime = Convert.ToDateTime(dateTimePickerEndTime.Text).Date;
                DataTable table = _bll.GetAllPerf(startTime, endTime);

                table.WriteXml(@"C:\WINDOWS\xmlData\ComPerf.xml", XmlWriteMode.WriteSchema);

                FastReport.Report fasrReport = new Report();
                fasrReport.Preview = previewControl1;
                fasrReport.Load(Application.StartupPath + "\\Report\\frxComPerf.frx");
                fasrReport.SetParameterValue("ParaStartTime", startTime.ToString());
                fasrReport.SetParameterValue("ParaEndTime", endTime.ToString());

                previewControl1.Refresh();
                previewControl1.Show();
                fasrReport.Show();
            }catch(Exception ex)
            {
                MessageBox.Show("读取数据失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void FrmComPerf_FormClosing(object sender, FormClosingEventArgs e)
        {
            instance = null;
        }

    
    }
}
